#define _CRT_SECURE_NO_WARNINGS 1
#include"cplistt.h"

SLTNote* BuyNewNote(SLDatatype x)
{
	struct SList* tail = (struct SList*)malloc(sizeof(SLTNote));
	if (tail == NULL)
	{
		perror("malloc");
		return NULL;
	}
	tail->data = x;
	tail->next = NULL;
	return tail;
}
void SLPushFront(SLTNote** pphead, SLDatatype x)
{
	SLTNote* tail = BuyNewNote(x);
	tail->next = *pphead;
	*pphead = tail;
}
void SLPustBack(SLTNote** pphead, SLDatatype x)
{
	SLTNote* newnote = BuyNewNote(x);
	if (*pphead == NULL)
	{
		*pphead = newnote;
	}
	else
	{
		SLTNote* tail = *pphead;
		while (tail->next != NULL)
		{
			tail = tail->next;
		}
		tail->next = newnote;
	}
}
void SLPopBack(SLTNote** pphead)
{
	assert(*pphead);
	/*if ((*pphead)->next == NULL)
	{
		free(*pphead);
		*pphead = NULL;
	}
	else
	{
		SLTNote* pev = NULL;
		SLTNote* tail = *pphead;
		while (tail->next)
		{
			pev = tail;
			tail = tail->next;
		}
		free(tail);
		pev->next = NULL;
	}*/
	SLTNote* tail = *pphead;
	while (tail->next->next)
	{
		tail = tail->next;
	}
	free(tail->next);
	tail->next = NULL;
}
void SLPopBack(SLTNote** pphead)
{
	assert(*pphead);
	SLTNote* tail = *pphead;
	*pphead = (*pphead)->next;
	free(tail);
}